import base64
import pickle

from django.test import TestCase

# Create your tests here.
if __name__ == '__main__':
    cart_dict = {
        1: {
            'count': 2,
            'selected': True
        },
        3: {
            'count': 1,
            'selected': True
        },
        5: {
            'count': 1,
            'selected': True
        }
    }
    # 转换为字节流
    # res = pickle.dumps(cart_dict)
    # 利用base64编码
    # res = base64.b64encode(res)
    # 进行解码变为字符串
    # res = res.decode()
    res = base64.b64encode(pickle.dumps(cart_dict)).decode()
    print(res)


    # 解码

    res1 = res.encode()
    res1 = base64.b64decode(res1)
    res1_dict = pickle.loads(res1)
    print(res1_dict)
